package _11_binary_search_tree.exerc;

import _11_binary_search_tree.BSTree;
import org.junit.Test;


/**
 * @author: mornd
 * @dateTime: 2023/6/12 - 17:08
 */
public class MyTest {
    @Test
    public void testGet() {
        BSTree<String> tree = new BSTree<>();
        tree.root = new BSTree.BSTNode<>(10, "乔峰");
        tree.root.left = new BSTree.BSTNode<>(5, "段誉");
        tree.root.right = new BSTree.BSTNode<>(13, "虚竹");
        tree.root.left.left = new BSTree.BSTNode<>(3, "王语嫣");
        tree.root.left.right = new BSTree.BSTNode<>(7, "木婉清");
        tree.root.right.left = new BSTree.BSTNode<>(12, "慕容复");
        tree.root.right.right = new BSTree.BSTNode<>(15, "扫地僧");

        System.out.println(tree);
//        System.out.println(tree.get(7));

        System.out.println(tree.max());
        System.out.println(tree.min());
    }

    @Test
    public void testPut() {
        BSTree<String> tree = new BSTree<>();
        tree.put(4, "小龙女");
        tree.put(2, "黄蓉");
        tree.put(7, "张无忌");
        tree.put(1, "郭靖");
        tree.put(3, "杨过");
        tree.put(6, "岳灵珊");
        tree.put(8, "赵敏");
        tree.put(5, "令狐冲");
        tree.put(9, "段智兴");
        tree.put(10, "虚竹");
        System.out.println(tree);

//        for (int i = 1; i <= 10; i++) {
//            System.out.println(tree.successor(i));
//        }
//        System.out.println();
//
//        for (int i = 1; i <= 10; i++) {
//            System.out.println(tree.predecessor(i));
//        }
//        System.out.println(tree.successor(6));

//        System.out.println(tree.delete(4));
        System.out.println(tree.delete2(4));
        System.out.println();
        System.out.println(tree);
    }

    @Test
    public void testBetween() {
        BSTree<String> tree = new BSTree<>();
        tree.put(4, "小龙女");
        tree.put(2, "黄蓉");
        tree.put(7, "张无忌");
        tree.put(1, "郭靖");
        tree.put(3, "杨过");
        tree.put(6, "岳灵珊");
        tree.put(8, "赵敏");
        tree.put(5, "令狐冲");
        tree.put(9, "段智兴");
        tree.put(10, "虚竹");
        System.out.println(tree);

//        System.out.println(tree.le(7));
        System.out.println(tree.gt(3));

        System.out.println(tree.between(3, 8));

//        tree.root.right.left.left.key = 7;

        System.out.println(BSTree.isValidBST(tree));
        System.out.println(BSTree.isValidBST2(tree));
    }


    @Test
    public void testValid() {
        BSTree<Object> tree = new BSTree<>();
        BSTree.BSTNode<Object> root = new BSTree.BSTNode<>(4);
        root.left = new BSTree.BSTNode<>(2);
        root.right = new BSTree.BSTNode<>(6);
        root.right.left = new BSTree.BSTNode<>(3);
        root.right.right = new BSTree.BSTNode<>(7);
        tree.root = root;

        System.out.println(tree);
        System.out.println(BSTree.isValidBST(tree));
        System.out.println(BSTree.isValidBST2(tree));
    }
}
